package com.qf.controller;

import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileInputStream;

@Controller
public class downLoad {
    @RequestMapping("/downLoad")
    public void downLoad(String name, HttpSession session, HttpServletResponse response)throws Exception{
        System.out.println("name = " + name);
        String path = session.getServletContext().getRealPath("/upload");
        String filePath=path+File.separator+name;
        response.setHeader("content-disposition","attachment;filename="+name);
        IOUtils.copy(new FileInputStream(filePath),response.getOutputStream());
    }
}
